package com.wpw.dream.easyui.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("easyui")
public class EasyUIController {
	
	@RequestMapping("page/index")
	public ModelAndView toPageIndex() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("easyui/index");
		return mv;
	}
	
	@ResponseBody
	@RequestMapping("page/list")
	public Object page(HttpServletRequest request) {
		int pageNo = Integer.parseInt(request.getParameter("page"));
		int rows = Integer.parseInt(request.getParameter("rows"));
		String param = request.getParameter("param");
		
		Map<String, Object> resMap = new HashMap<>();
		List<Map<String, Object>> dataList = new ArrayList<>();
		Map<String, Object> data;
		for (int i = 0; i < rows; i++) {
			data = new HashMap<>();
			data.put("id", pageNo);
			data.put("name", param);
			dataList.add(data);
		}
		resMap.put("total", 111);
		resMap.put("rows", dataList);
		
		return resMap;
	}

}
